package icselab.util;

import java.io.InputStream;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource;

public class ConfigParser {

	public static final String CONFIGFILE = "Config.xml";
	
	public String getElement(String elementName){
		InputStream is = ConfigParser.class.getClassLoader().getResourceAsStream(CONFIGFILE);
		XPath xpathEngine = XPathFactory.newInstance().newXPath(); 
        String xpathExpression = "/config/"+elementName+"/text()"; 
        InputSource xmlSource = new InputSource(is);
        try {
			return xpathEngine.evaluate(xpathExpression, xmlSource);
		} catch (XPathExpressionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return null;
	}
}
